const Router = require('koa-router')

const router = new Router()


router.prefix('/api')

// 1. request method response
router.get('/', ctx => {
    console.log(ctx.request)
    ctx.body = 'Hello World!'
})

// http://localhost:3000/api/api?name=ionluo&age=25&pretty
router.get('/api', ctx => {
    const params = ctx.request.query
    console.log(params)
    ctx.body = params
})

router.post('/post', async ctx => {
    let { body } = ctx.request
    // response
    ctx.body = {
        ...body
    }
})


module.exports = router